<template>
    <div class="imginfo">
        <h3>{{imgInfo[0].title}}</h3>
        <p class="subtitle">
            <span>发表时间:{{imgInfo[0].add_time | dateForm}}</span>
            <span>点击次数:{{imgInfo[0].click}}次</span>
        </p>
        <hr>
        <div class='imgs'>
            <viewer :images="list">
                <img v-for="item in list" :src="item.src" :key="item.src" height="100" title="点击可预览全部图片">
            </viewer>
        </div>
        
        <div class="content" v-html='imgInfo[0].content'></div>
        <!--评论子组件-->
        <hr>
        <comment-box :id1="this.id"></comment-box>
    </div>
</template>

<script>
import comment from '../subcomponents/comment.vue';
export default {
    data(){
        return {
            id: this.$route.params.id,
            imgInfo:{},
            list:[]//小图地址
        }
    },
    created(){
        this.getPhotoInfoById();
        this.getThumListById();
    },
    methods:{
        getPhotoInfoById(){
            //获取图片的详情
            this.$http.get('http://www.liulongbin.top:3005/api/getimageinfo/'+this.id).then(result => {
                if(result.body.status === 0){
                    this.imgInfo = result.body.message;
                }
            })
        },
        getThumListById(){
            //获取图片的详情
            this.$http.get('http://www.liulongbin.top:3005/api/getthumimages/'+this.id).then(result => {
                if(result.body.status === 0){
                    //循环图片数据，事先补全图片的宽和高
                    result.body.message.forEach(item =>{
                        item.w = 600;
                        item.h = 400;
                    });
                    this.list  = result.body.message;
                }
            })
        }
    },
    components:{
        'comment-box':comment
    }
}
</script>

<style lang="scss" scoped>
.imginfo{
    padding: 3px;
    h3{
        color: #26a2ff;
        font-size: 15px;
        text-align: center;
        margin: 10px auto; 
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        margin: 0;
        padding: 0;
    }
    .content{
        font-size: 13px;
        line-height: 30px;
    }
    .imgs{
        div{
           
            margin-left:2%;
        }
        img{
            margin: 6px;
        }
    }

}
</style>